#include <iostream>
#include <iomanip>
#include <vector>

using namespace std;

void main()
{
	vector <int> vec(10);
	int n;
	int primecount = 0, i, j;
	
	cout << "Enter a value >= 2 as upper limit for prime numbers:";
	cin >> n;
	vec[primecount++] = 2;

	for (i = 3; i < n; i++)
	{
		if (primecount == vec.size())
			vec.resize(primecount + 10);

		if (i % 2 == 0)
			continue;

		j = 3;
		while (j <= i / 2 && i % j != 0)
			j += 2;

		if (j > i / 2)
			vec[primecount++] = i;
	}

	for (i = 0; i < primecount; i++)
	{
		cout << setw(5) << vec[i];
		if ((i + 1) % 10 == 0)
			cout << endl;
	}

	cout << endl;
}